Using Timers and Simulation Time

Number GetTimeSinceStart();

Gets the number of milliseconds that have elapsed since the start of the simulation

Parameters - None

Return Value Milliseconds since simulation start, this is a 32-bit value that will wrap every 49 days.

LogInfo("Number of milliseconds since simulation started = " + GetTimeSinceStart());
			

Number GetSecondsSinceMidnight();

Parameters - NONE

Return Value - A number that represents the number of seconds that have elapsed since midnight of day 1 of the simulation.

LogInfo("Number of seconds since midnight of day 1 of the simulation = " + GetSecondsSinceMidnight());

Date GetSimulationDateTime()

Parameters - NONE

Return Value - A Date object that represents the current simulation time

var currentDate = GetSimulationDateTime();
var date = currentDate.getDate();
var month = currentDate.getMonth(); //Be careful! January is 0 not 1
var year = currentDate.getFullYear();
LogInfo("Get simulation date object = " + date + " | " + month + " | " + year);				
			

void SetTimerEx(timerID: integer, delay: integer, callback: object, param: object);

Set a callback event that will be invoked after a specified time delay

Parameters

Name Type

Description

timerID integer An identifier that will distinguish this time from another. This value is passed into the callback function as a parameter. It is also used to stop the timer prior to callback (see KillTimer)
delay integer This is the delay in milliseconds that will elapse before the callback is invoked. The context of this delay value is simulation time, so time warping will apply.
callback object Can be a string (The name of the function) or the function that will be invoked when the specified time delay has expired.
param Object An object that is to be used within the callback method. This object may be any type or null.

Return Value - void.

 

Example 1:

SetTimerEx(1, 1000, "CallMeWhenTimerExpires", GetComponentByNameAndType("CC1", "Conveyor") );
...
function CallMeWhenTimerExpires(timerId, object) {
  LogDebug("Timer " + timerId + " expires for " + object.Name);
}

Example 2:

 
SetTimerEx(1, 1000,Test, GetComponentByNameAndType("CC1", "Conveyor"));
...	
function Test (timerId, object){
LogDebug("Timer " + timerId + " expires for " + object.Name);
}

 

void KillTimer(timerID: integer);

Stops the callback for a timer previously created with the ‘SetTimerEx’ method.

Parameters

Name Type

Description

TimerID int The identifier of the timer

Return Value - void.

 

It is only necessary to use KillTimer when the Timer has not expired to prevent the callback from being called. Once the Timer expires it is automatically removed.

void SetTimer(callbackMethodName: string, delay: integer, componentName: string); DEPRECATED, use SetTimerEx instead.

Set a callback event that will be invoked after a specified time delay

Parameters

Name Type Description
callbackMethodName String The name of the method that will be invoked when the specified time delay has expired. This method must take a single object that will be an instance of the component specified in the ‘componentName’ parameter
delay int This is the delay in milliseconds that will elapse before the callback is invoked. The context of this delay value is simulation time, so time warping will apply.
componentName

 

The name of the component that will be passed in as the first parameter of the callback function

Return Value - void.